bitkeeper revision 1.304.1.2 (3f0bdd80mrpM9InfprcL835uydvRVA)
authorrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Wed, 9 Jul 2003 09:16:48 +0000 (09:16 +0000)
committerrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Wed, 9 Jul 2003 09:16:48 +0000 (09:16 +0000)
Small bug fix for Extent constructor parameter ordering
Reformatting, cleanups, adjust the usage/help messages for Parse* to make more sense
Make ParseHelp throw slightly less exceptions =)

20 files changed:
tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java
tools/control/src/org/xenoserver/cmdline/ParseDomainList.java
tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java
tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java
tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java
tools/control/src/org/xenoserver/cmdline/ParseFailedException.java
tools/control/src/org/xenoserver/cmdline/ParseHelp.java
tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java
tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java
tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java
tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
tools/control/src/org/xenoserver/cmdline/ParseVdFree.java
tools/control/src/org/xenoserver/cmdline/ParseVdRefresh.java
tools/control/src/org/xenoserver/cmdline/ParseVdShow.java
tools/control/src/org/xenoserver/control/CommandPhysicalList.java
tools/control/src/org/xenoserver/control/VirtualDisk.java
tools/control/src/org/xenoserver/control/XMLHelper.java

index 799a9537724fceede93f98583f28fdb48dd56402..78d224cf5e6a4e5d302f58ae168816de3204748d 100644 (file)
@@ -7,32 +7,30 @@ import org.xenoserver.control.CommandFailedException;
 import org.xenoserver.control.Defaults;
 
 public class ParseDomainDestroy extends CommandParser {
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    int domain_id = getIntParameter(args, 'n', 0);
-    boolean force = getFlagParameter(args, 'f');
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        int domain_id = getIntParameter(args, 'n', 0);
+        boolean force = getFlagParameter(args, 'f');
 
-    if (domain_id == 0) {
-      throw new ParseFailedException("Expected -n<domain_id>");
+        if (domain_id == 0) {
+            throw new ParseFailedException("Expected -n<domain_id>");
+        }
+
+        String output = new CommandDomainDestroy(d, domain_id, force).execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+    }
+
+    public String getName() {
+        return "destroy";
     }
 
-    String output = new CommandDomainDestroy(d, domain_id, force).execute();
-    if ( output != null )
-      System.out.println( output );
-  }
-  
-  public String getName()
-  {
-    return "destroy";
-  }
-
-  public String getUsage()
-  {
-    return "[-f] [-n<domain_id>]";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "Destory the specified domain.  -f forcibly destroys it.";
-  }
+    public String getUsage() {
+        return "-n<domain_id> [-f]";
+    }
+
+    public String getHelpText() {
+        return "Destroy the specified domain.  -f forcibly destroys it.";
+    }
 }
index bf36252e1d05fcab7d6d9255b58cf0ec66201013..4d3a1fecf174ddbce9ede8a986c0ec31e62b77b5 100644 (file)
@@ -8,40 +8,37 @@ import org.xenoserver.control.Defaults;
 import org.xenoserver.control.Domain;
 
 public class ParseDomainList extends CommandParser {
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        CommandDomainList list = new CommandDomainList(d);
+        String output = list.execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+
+        Domain[] domains = list.domains();
+
+        for (int loop = 0; loop < domains.length; loop++) {
+            System.out.println(
+                "id: " + domains[loop].id + " (" + domains[loop].name + ")");
+            System.out.println("  processor: " + domains[loop].processor);
+            System.out.println("  has cpu: " + domains[loop].cpu);
+            System.out.println(
+                "  state: " + domains[loop].nstate + " " + domains[loop].state);
+            System.out.println("  mcu advance: " + domains[loop].mcu);
+            System.out.println("  total pages: " + domains[loop].pages);
+        }
+    }
+
+    public String getName() {
+        return "list";
+    }
+
+    public String getUsage() {
+        return "";
+    }
 
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    CommandDomainList list = new CommandDomainList(d);
-    String output = list.execute();
-    if ( output != null )
-      System.out.println( output );
-    Domain[] domains = list.domains();
-
-    for (int loop = 0; loop < domains.length; loop++)
-    {
-      System.out.println ("id: " + domains[loop].id + 
-        " (" + domains[loop].name+ ")");
-      System.out.println ("  processor: " + domains[loop].processor);
-      System.out.println ("  has cpu: " + domains[loop].cpu);
-      System.out.println ("  state: " + domains[loop].nstate + " " +
-        domains[loop].state);
-      System.out.println ("  mcu advance: " + domains[loop].mcu);
-      System.out.println ("  total pages: " + domains[loop].pages);
+    public String getHelpText() {
+        return "List domain information and status.";
     }
-  }
-
-  public String getName()
-  {
-    return "list";
-  }
-
-  public String getUsage()
-  {
-    return "";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "List domain information";
-  }
 }
index 069d439b16158fe2ca01f9bafad90c99949b6d18..080e8a3d2b138693b0278099d3044aa24b8a3ada 100644 (file)
@@ -7,76 +7,86 @@ import org.xenoserver.control.CommandFailedException;
 import org.xenoserver.control.Defaults;
 
 public class ParseDomainNew extends CommandParser {
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        String name = getStringParameter(args, 'n', d.domainName);
+        int size = getIntParameter(args, 'k', d.domainSizeKB);
+        String image = getStringParameter(args, 'i', d.domainImage);
+        String initrd = getStringParameter(args, 'r', d.domainInitRD);
+        int vifs = getIntParameter(args, 'v', d.domainVIFs);
+        String bargs = getStringParameter(args, 'a', d.args) + " ";
+        String root_dev = getStringParameter(args, 'd', d.rootDevice);
+        String nfs_root_path = getStringParameter(args, 'f', d.nwNFSRoot);
+        String nw_ip = getStringParameter(args, '4', d.nwIP);
+        String nw_gw = getStringParameter(args, 'g', d.nwGateway);
+        String nw_mask = getStringParameter(args, 'm', d.nwMask);
+        String nw_nfs_server = getStringParameter(args, 's', d.nwNFSServer);
+        String nw_host = getStringParameter(args, 'h', d.nwHost);
 
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    String name = getStringParameter(args, 'n', d.domainName);
-    int size = getIntParameter(args, 'k', d.domainSizeKB);
-    String image = getStringParameter(args, 'i', d.domainImage);
-    String initrd = getStringParameter (args, 'r', d.domainInitRD);
-    int vifs = getIntParameter(args, 'v', d.domainVIFs);
-    String bargs = getStringParameter (args, 'a', d.args) + " ";
-    String root_dev = getStringParameter (args, 'd', d.rootDevice);
-    String nfs_root_path = getStringParameter (args, 'f', d.nwNFSRoot);
-    String nw_ip = getStringParameter (args, '4', d.nwIP);
-    String nw_gw = getStringParameter (args, 'g', d.nwGateway);
-    String nw_mask = getStringParameter (args, 'm', d.nwMask);
-    String nw_nfs_server = getStringParameter (args, 's', d.nwNFSServer);
-    String nw_host = getStringParameter (args, 'h', d.nwHost);
+        d.describe();
 
-    d.describe();
+        CommandDomainNew c =
+            new CommandDomainNew(
+                d,
+                name,
+                size,
+                image,
+                initrd,
+                vifs,
+                bargs,
+                root_dev,
+                nfs_root_path,
+                nw_ip,
+                nw_gw,
+                nw_mask,
+                nw_nfs_server,
+                nw_host);
+        c.execute();
+        String[] output = c.output();
+        for (int i = 0; i < output.length; i++) {
+            System.out.println(output[i]);
+        }
+    }
 
-    CommandDomainNew c = new CommandDomainNew(d, name, size, image, initrd, vifs,
-                                  bargs, root_dev, nfs_root_path,
-                                  nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host);
-    c.execute();
-    String[] output = c.output();
-    for ( int i = 0; i < output.length; i++ )
-      System.out.println( output[i] ); 
-  }
+    public String getName() {
+        return "new";
+    }
 
-  public String getName()
-  {
-    return "new";
-  }
+    public String getUsage() {
+        return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
+    }
 
-  public String getUsage()
-  {
-    return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "Create a new domain.  Note that most of the parameters will assume\n" +
-      "default values: it should not be necessary to specify them all. See\n" +
-      "domctl.xml for the current default settings.\n" +
-      "\n" +
-      "General command line options:\n" +
-      "  -n  Domain name                              domain_name\n" +
-      "  -k  Domain size (kb)                         domain_size_kb\n" +
-      "  -i  Domain image name                        domain_image\n" +
-      "  -v  Number of VIFs                           domain_vifs\n" +
-      "  -r  InitRD (if required)                     domain_init_rd\n" +
-      "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n" +
-      "  -a  Additional boot parameters\n" +
-      "\n" +
-      "Networking options:\n" +
-      "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n" +
-      "  -s  NFS server                               nw_nfs_server\n" +
-      "  -4  Domain IPv4 address                      nw_ip\n" +
-      "  -g  Domain gateway                           nw_gw\n" +
-      "  -m  Domain net mask                          nw_mask\n" +
-      "  -h  Domain hostname                          nw_host\n" +
-      "\n" +
-      "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
-      "which the allocated domain ID will be incorporated.  e.g.  for\n" +
-      "domain 1 patterns would expand as follows:\n" +
-      "\n" +
-      "  /dev/hda+       /dev/hda1\n" +
-      "  /dev/hda7+      /dev/hda8\n" +
-      "  128.232.8.50+   128.232.8.51\n" +
-      "\n" +
-      "Additionally, patterns for -4 -g -m can include an = which is\n" + 
-      "expanded to the corresponding setting from the calling domain.\n";
-  }
+    public String getHelpText() {
+        return "Create a new domain.  Note that most of the parameters will assume\n"
+            + "default values: it should not be necessary to specify them all. See\n"
+            + "domctl.xml for the current default settings.\n"
+            + "\n"
+            + "General command line options:\n"
+            + "  -n  Domain name                              domain_name\n"
+            + "  -k  Domain size (kb)                         domain_size_kb\n"
+            + "  -i  Domain image name                        domain_image\n"
+            + "  -v  Number of VIFs                           domain_vifs\n"
+            + "  -r  InitRD (if required)                     domain_init_rd\n"
+            + "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n"
+            + "  -a  Additional boot parameters\n"
+            + "\n"
+            + "Networking options:\n"
+            + "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n"
+            + "  -s  NFS server                               nw_nfs_server\n"
+            + "  -4  Domain IPv4 address                      nw_ip\n"
+            + "  -g  Domain gateway                           nw_gw\n"
+            + "  -m  Domain net mask                          nw_mask\n"
+            + "  -h  Domain hostname                          nw_host\n"
+            + "\n"
+            + "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n"
+            + "which the allocated domain ID will be incorporated.  e.g.  for\n"
+            + "domain 1 patterns would expand as follows:\n"
+            + "\n"
+            + "  /dev/hda+       /dev/hda1\n"
+            + "  /dev/hda7+      /dev/hda8\n"
+            + "  128.232.8.50+   128.232.8.51\n"
+            + "\n"
+            + "Additionally, patterns for -4 -g -m can include an = which is\n"
+            + "expanded to the corresponding setting from the calling domain.\n";
+    }
 }
index 826057188f1762055a99502e29f9a82e283637de..e27394cb23f0f0e163ef2c1670f2fc3de771f6b2 100644 (file)
@@ -7,32 +7,28 @@ import org.xenoserver.control.CommandFailedException;
 import org.xenoserver.control.Defaults;
 
 public class ParseDomainStart extends CommandParser {
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        int domain_id = getIntParameter(args, 'n', 0);
 
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    int domain_id = getIntParameter(args, 'n', 0);
-    
-    if (domain_id == 0) {
-      throw new ParseFailedException("Expected -n<domain_id>");
+        if (domain_id == 0) {
+            throw new ParseFailedException("Expected -n<domain_id>");
+        }
+
+        String output = new CommandDomainStart(d, domain_id).execute();
+        if (output != null)
+            System.out.println(output);
+    }
+
+    public String getName() {
+        return "start";
     }
 
-    String output = new CommandDomainStart(d, domain_id).execute();
-    if ( output != null )
-      System.out.println( output );
-  }
-
-  public String getName()
-  {
-    return "start";
-  }
-
-  public String getUsage()
-  {
-    return "[-n<domain_id>]";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "Start the specified domain.";
-  }
+    public String getUsage() {
+        return "-n<domain_id>";
+    }
+
+    public String getHelpText() {
+        return "Start the specified domain.";
+    }
 }
index c2a9f1093be2124f8c62bcacefac15f397014c5a..306f18529b7f719c6aaac8ba0129a2bf75fefd7e 100644 (file)
@@ -7,32 +7,28 @@ import org.xenoserver.control.CommandFailedException;
 import org.xenoserver.control.Defaults;
 
 public class ParseDomainStop extends CommandParser {
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        int domain_id = getIntParameter(args, 'n', 0);
 
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    int domain_id = getIntParameter(args, 'n', 0);
-    
-    if (domain_id == 0) {
-      throw new ParseFailedException("Expected -n<domain_id>");
+        if (domain_id == 0) {
+            throw new ParseFailedException("Expected -n<domain_id>");
+        }
+
+        String output = new CommandDomainStop(d, domain_id).execute();
+        if (output != null)
+            System.out.println(output);
+    }
+
+    public String getName() {
+        return "stop";
     }
 
-    String output = new CommandDomainStop(d, domain_id).execute();
-    if ( output != null )
-      System.out.println( output );
-  }
-
-  public String getName()
-  {
-    return "stop";
-  }
-
-  public String getUsage()
-  {
-    return "[-n<domain_id>]";
-  }
-
-  public String getHelpText()
-  {
-    return
-      "Stop the specified domain.";
-  }
+    public String getUsage() {
+        return "-n<domain_id>";
+    }
+
+    public String getHelpText() {
+        return "Stop the specified domain.";
+    }
 }
index 6e51be32a1e41b7e789a5b78f343e1707dd14dcc..4f084cdb9b20cc7c88ced8113ca8b110309599ba 100644 (file)
@@ -4,19 +4,11 @@ package org.xenoserver.cmdline;
  * Thrown when a command line could not be parsed.
  */
 public class ParseFailedException extends Exception {
-  public ParseFailedException() {
-    super();
-  }
+    public ParseFailedException(String message) {
+        super(message);
+    }
 
-  public ParseFailedException(String message) {
-    super(message);
-  }
-
-  public ParseFailedException(String message, Throwable cause) {
-    super(message, cause);
-  }
-
-  public ParseFailedException(Throwable cause) {
-    super(cause);
-  }
+    public ParseFailedException(String message, Throwable cause) {
+        super(message, cause);
+    }
 }
index a9a7138e850d6b075a16842251b79d7c99fc8b0e..8106116aaf5e7e8066cc1b840ac938aac643da0e 100644 (file)
@@ -5,31 +5,27 @@ import java.util.LinkedList;
 import org.xenoserver.control.Defaults;
 
 public class ParseHelp extends CommandParser {
+    public void parse(Defaults d, LinkedList args) {
+        if (args == null || args.isEmpty()) {
+            System.out.println("Usage:");
+            Main.parser.printUsage(null);
+        } else {
+            System.out.print("xenctl ");
+            Main.parser.printHelpText(args);
+        }
 
-  public void parse(Defaults d, LinkedList args) {
-    if (args.size() == 0) {
-      System.out.println("Usage:");
-      Main.parser.printUsage(null);
-    } else {
-      System.out.print("xenctl ");
-      Main.parser.printHelpText(args);
+        System.out.println("");
     }
 
-    System.out.println("");
-  }
-  
-  public String getName()
-  {
-    return "help";
-  }
+    public String getName() {
+        return "help";
+    }
 
-  public String getUsage()
-  {
-    return "";
-  }
+    public String getUsage() {
+        return "[<any command>]";
+    }
 
-  public String getHelpText()
-  {
-    return "This message";
-  }  
+    public String getHelpText() {
+        return "This message, or if a command is specified, help for that command.";
+    }
 }
index 67e4902b9b5f79e83cb256f102587316e8e2b81c..041e222b4fc2543a8c0561151d84c9ccd9ec9c27 100644 (file)
@@ -14,30 +14,34 @@ public class ParsePartitionsAdd extends CommandParser {
   public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
     boolean force = getFlagParameter(args, 'f');
     String partition_name = getStringParameter(args, 'p', "");
-    String size = getStringParameter(args, 'c', "100M");
+    String size = getStringParameter(args, 'c', "128M");
     
-    if (partition_name.equals(""))
+    if (partition_name.equals("")) {
       throw new ParseFailedException("Expected -p<partition_name>");
+    }
       
     long chunksize = Library.parseSize( size ) / Settings.SECTOR_SIZE;
-    if ( chunksize <= 0 )
+    if ( chunksize <= 0 ) {
       throw new CommandFailedException("Chunk size " + size + " is smaller than sector size.");
+    }
     
     // Initialise the partition manager and look up the partition
     loadState();
     Partition p = PartitionManager.IT.getPartition(partition_name);
     
-    if ( p == null )
+    if ( p == null ) {
       throw new CommandFailedException("Partition " + partition_name + " does not exist.");
+    }
     
     // Check if this partition belongs to the VDM
-    if (p.isXeno() && !force)
+    if (p.isXeno() && !force) {
       throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure.");
+    }
     
     String output = new CommandPartitionAdd( p, chunksize ).execute();
-    if ( output != null )
+    if ( output != null ) {
       System.out.println( output );
-      
+    }
     saveState();
   }
 
@@ -46,7 +50,7 @@ public class ParsePartitionsAdd extends CommandParser {
   }
 
   public String getUsage() {
-    return "[-f] [-p<partition_name>] [-c<chunk_size>]";
+    return "-p<partition_name> [-f] [-c<chunk_size>]";
   }
 
   public String getHelpText() {
index ac60c6e591cd02513acf8d721351b3c01b5277a0..40388a7f5f4737a8173f545c60cc5bc0f6ce96a8 100644 (file)
@@ -10,45 +10,56 @@ import org.xenoserver.control.Partition;
 import org.xenoserver.control.PartitionManager;
 
 public class ParsePartitionsList extends CommandParser {
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    loadState();
-    Iterator i = PartitionManager.IT.iterator();
-    int idx = 1;
-    System.out.println( "     maj:min " + "    blocks " + "start sect " +
-                        " num sects " + "name" );
-    while (i.hasNext()) {
-      Partition p = (Partition) i.next();
-
-      if (p.isXeno()) {
-        System.out.print("[ ");
-      } else {
-        System.out.print("  ");
-      }
-      System.out.print(Library.format(idx++, 2, false) + " ");
-      System.out.print(Library.format(p.getMajor(),3,false) + ":" + 
-          Library.format(p.getMinor(),3,true) + " " +
-          Library.format(p.getBlocks(),10,false) + " " +
-          Library.format(p.getStartSect(),10,false) + " " +
-          Library.format(p.getNumSects(),10,false) + " " +
-          Library.format(p.getName(),7,true));   
-      if (p.isXeno()) {
-        System.out.println("]");
-      } else {
-        System.out.println();
-      }
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        loadState();
+        Iterator i = PartitionManager.IT.iterator();
+        int idx = 1;
+        System.out.println(
+            "     maj:min "
+                + "    blocks "
+                + "start sect "
+                + " num sects "
+                + "name");
+        while (i.hasNext()) {
+            Partition p = (Partition) i.next();
+
+            if (p.isXeno()) {
+                System.out.print("[ ");
+            } else {
+                System.out.print("  ");
+            }
+            System.out.print(Library.format(idx++, 2, false) + " ");
+            System.out.print(
+                Library.format(p.getMajor(), 3, false)
+                    + ":"
+                    + Library.format(p.getMinor(), 3, true)
+                    + " "
+                    + Library.format(p.getBlocks(), 10, false)
+                    + " "
+                    + Library.format(p.getStartSect(), 10, false)
+                    + " "
+                    + Library.format(p.getNumSects(), 10, false)
+                    + " "
+                    + Library.format(p.getName(), 7, true));
+            if (p.isXeno()) {
+                System.out.println("]");
+            } else {
+                System.out.println();
+            }
+        }
     }
-  }
 
-  public String getName() {
-    return "list";
-  }
+    public String getName() {
+        return "list";
+    }
 
-  public String getUsage() {
-    return "";
-  }
+    public String getUsage() {
+        return "";
+    }
 
-  public String getHelpText() {
-    return "List real partition information";
-  }
+    public String getHelpText() {
+        return "List physical partition information. Partitions surrounded by [] are XenoPartitions.";
+    }
 
 }
index 629d2cb3bf8180e751125d8791b6a8c0d6615dee..60cb925dd1b35a83d2d09b853a5152496c98b692 100644 (file)
@@ -16,31 +16,37 @@ public class ParsePhysicalGrant extends CommandParser {
     String partition_name = getStringParameter(args, 'p', "");
     boolean write = getFlagParameter(args, 'w');
     
-    if (domain_id == 0)
+    if (domain_id == 0) {
       throw new ParseFailedException("Expected -n<domain_id>");
-    if (partition_name.equals(""))
+    }
+    if (partition_name.equals("")) {
       throw new ParseFailedException("Expected -p<partition_name>");
+    }
       
     Mode mode;
-    if (write)
+    if (write) {
       mode = Mode.READ_WRITE;
-    else
+    } else {
       mode = Mode.READ_ONLY;
+    }
       
     // Initialise the partition manager and look up the partition
     loadState();
     Partition p = PartitionManager.IT.getPartition(partition_name);
     
-    if ( p == null )
+    if ( p == null ) {
       throw new CommandFailedException("Partition " + partition_name + " does not exist.");
+    }
     
     // Check if this partition belongs to the VDM
-    if (p.isXeno() && !force)
+    if (p.isXeno() && !force) {
       throw new CommandFailedException("Refusing to grant physical access as the given partition is allocated to the virtual disk manager. Use -f if you are sure.");
-     
+    }
+         
     String output = new CommandPhysicalGrant( d, domain_id, p, mode ).execute();
-    if ( output != null )
+    if ( output != null ) {
       System.out.println( output );
+    }
   }
 
   public String getName() {
@@ -48,7 +54,7 @@ public class ParsePhysicalGrant extends CommandParser {
   }
 
   public String getUsage() {
-    return "[-f] [-w] [-n<domain_id>] [-p<partition_name>]";
+    return "-n<domain_id> -p<partition_name> [-f] [-w]";
   }
 
   public String getHelpText() {
index 18a4400e80f406aefd1a28a61e20ddc95592f097..1b662aa06976d1ddb059516434f86ed3d53b8820 100644 (file)
@@ -13,59 +13,82 @@ import org.xenoserver.control.Partition;
 import org.xenoserver.control.PartitionManager;
 
 public class ParsePhysicalList extends CommandParser {
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        int domain_id = getIntParameter(args, 'n', 0);
+        if (domain_id == 0) {
+            throw new ParseFailedException("Expected -n<domain_id>");
+        }
 
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    int domain_id = getIntParameter(args, 'n', 0);
-    if (domain_id == 0)
-      throw new ParseFailedException("Expected -n<domain_id>");
+        // Initialise the partition manager
+        loadState();
 
-    // Initialise the partition manager
-    loadState();
-    
-    CommandPhysicalList list = new CommandPhysicalList( d, domain_id );
-    String output = list.execute();
-    if ( output != null )
-      System.out.println( output );
-      
-    System.out.println( "maj:min " + "    blocks " + "start sect " +
-                        " num sects " + "name    " + "access" );
-    Iterator i = list.extents().entrySet().iterator();
-    while ( i.hasNext() )
-    {
-      Entry entry = (Entry) i.next(); 
-      Extent e = (Extent) entry.getKey();
-      String mode = entry.getValue().toString();
-      Partition p = PartitionManager.IT.getPartition( e );
-      if ( p != null ) {
-        System.out.println(Library.format(p.getMajor(),3,false) + ":" + 
-          Library.format(p.getMinor(),3,true) + " " +
-          Library.format(p.getBlocks(),10,false) + " " +
-          Library.format(p.getStartSect(),10,false) + " " +
-          Library.format(p.getNumSects(),10,false) + " " +
-          Library.format(p.getName(),7,true) + " " +
-          Library.format(mode,2,true));   
-      } else {
-        System.out.println(Library.format(e.getMajor(),3,false) + ":" +
-          Library.format(e.getMinor(),3,true) + " " +
-          "          " + " " +
-          Library.format(e.getOffset(),10,false) + " " +
-          Library.format(e.getSize(),10,false) + " " +
-          "       " + " " +
-          Library.format(mode,2,true));
-      }
+        CommandPhysicalList list = new CommandPhysicalList(d, domain_id);
+        String output = list.execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+
+        System.out.println(
+            "maj:min "
+                + "    blocks "
+                + "start sect "
+                + " num sects "
+                + "name    "
+                + "access");
+        Iterator i = list.extents().entrySet().iterator();
+        while (i.hasNext()) {
+            Entry entry = (Entry) i.next();
+            Extent e = (Extent) entry.getKey();
+            String mode = entry.getValue().toString();
+            Partition p = PartitionManager.IT.getPartition(e);
+            if (p != null) {
+                System.out.println(
+                    Library.format(p.getMajor(), 3, false)
+                        + ":"
+                        + Library.format(p.getMinor(), 3, true)
+                        + " "
+                        + Library.format(p.getBlocks(), 10, false)
+                        + " "
+                        + Library.format(p.getStartSect(), 10, false)
+                        + " "
+                        + Library.format(p.getNumSects(), 10, false)
+                        + " "
+                        + Library.format(p.getName(), 7, true)
+                        + " "
+                        + Library.format(mode, 2, true));
+            } else {
+                System.out.println(
+                    Library.format(e.getMajor(), 3, false)
+                        + ":"
+                        + Library.format(
+                            e.getMinor() | e.getPartitionNo(),
+                            3,
+                            true)
+                        + " "
+                        + "          "
+                        + " "
+                        + Library.format(e.getOffset(), 10, false)
+                        + " "
+                        + Library.format(e.getSize(), 10, false)
+                        + " "
+                        + "       "
+                        + " "
+                        + Library.format(mode, 2, true));
+            }
+        }
     }
-  }
 
-  public String getName() {
-    return "list";
-  }
+    public String getName() {
+        return "list";
+    }
 
-  public String getUsage() {
-    return "[-n<domain_id>]";
-  }
+    public String getUsage() {
+        return "-n<domain_id>";
+    }
 
-  public String getHelpText() {
-    return "List all physical access which the given domain has been granted.";
-  }
+    public String getHelpText() {
+        return "List all physical access which the given domain has been granted.";
+    }
 
 }
index a5c90a720d04727e1faf78cd9081a24adc2750f1..1f075b470865315449d32186ce58c4024556d870 100644 (file)
@@ -9,37 +9,43 @@ import org.xenoserver.control.Partition;
 import org.xenoserver.control.PartitionManager;
 
 public class ParsePhysicalRevoke extends CommandParser {
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    int domain_id = getIntParameter(args, 'n', 0);
-    String partition_name = getStringParameter(args, 'p', "");
-    
-    if (domain_id == 0)
-      throw new ParseFailedException("Expected -n<domain_id>");
-    if (partition_name.equals(""))
-      throw new ParseFailedException("Expected -p<partition_name>");
-      
-    // Initialise the partition manager and look up the partition
-    loadState();
-    Partition p = PartitionManager.IT.getPartition(partition_name);
-    
-    if ( p == null )
-      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
-
-    String output = new CommandPhysicalRevoke( d, domain_id, p ).execute();
-    if ( output != null )
-      System.out.println( output );
-  }
-
-  public String getName() {
-    return "revoke";
-  }
-
-  public String getUsage() {
-    return "[-n<domain_id>] [-p<partition_name>]";
-  }
-
-  public String getHelpText() {
-    return "Revoke access to the given partition from the specified domain.";
-  }
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        int domain_id = getIntParameter(args, 'n', 0);
+        String partition_name = getStringParameter(args, 'p', "");
+
+        if (domain_id == 0) {
+            throw new ParseFailedException("Expected -n<domain_id>");
+        }
+        if (partition_name.equals("")) {
+            throw new ParseFailedException("Expected -p<partition_name>");
+        }
+
+        // Initialise the partition manager and look up the partition
+        loadState();
+        Partition p = PartitionManager.IT.getPartition(partition_name);
+
+        if (p == null) {
+            throw new CommandFailedException(
+                "Partition " + partition_name + " does not exist.");
+        }
+
+        String output = new CommandPhysicalRevoke(d, domain_id, p).execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+    }
+
+    public String getName() {
+        return "revoke";
+    }
+
+    public String getUsage() {
+        return "-n<domain_id> -p<partition_name>";
+    }
+
+    public String getHelpText() {
+        return "Revoke access to the given partition from the specified domain.";
+    }
 
 }
index 4f4210f22fbbadc440fc0745de43fbba81546d38..3aaeb967acee4cafddf2953adb0f365e1a4394e8 100644 (file)
@@ -1,5 +1,7 @@
 package org.xenoserver.cmdline;
 
+import java.text.DateFormat;
+import java.text.ParseException;
 import java.util.Date;
 import java.util.LinkedList;
 
@@ -10,40 +12,52 @@ import org.xenoserver.control.Library;
 import org.xenoserver.control.Settings;
 
 public class ParseVdCreate extends CommandParser {
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    String name = getStringParameter(args,'n',"");
-    String size_s = getStringParameter(args,'s',"");
-    String expiry_s = getStringParameter(args,'e',"");
-    Date expiry;
-    
-    if ( name.equals("") )
-      throw new ParseFailedException("Expected -n<name>");
-    if ( size_s.equals("") )
-      throw new ParseFailedException("Expected -s<size>");
-    if ( expiry_s.equals("") )
-      expiry = null;
-    else
-      expiry = new Date(Date.parse(expiry_s));
-      
-    long size = Library.parseSize(size_s);
-    
-    loadState();
-    String output = new CommandVdCreate(name,size/Settings.SECTOR_SIZE,expiry).execute();
-    if ( output != null )
-      System.out.println( output );
-    saveState();
-  }
-
-  public String getName() {
-    return "create";
-  }
-
-  public String getUsage() {
-    return "[-n<name>] [-s<size>] [-e<expiry>]";
-  }
-
-  public String getHelpText() {
-    return "Create a new virtual disk with the specified parameters";
-  }
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        String name = getStringParameter(args, 'n', "");
+        String size_s = getStringParameter(args, 's', "");
+        String expiry_s = getStringParameter(args, 'e', "");
+        Date expiry;
+
+        if (name.equals("")) {
+            throw new ParseFailedException("Expected -n<name>");
+        }
+        if (size_s.equals("")) {
+            throw new ParseFailedException("Expected -s<size>");
+        }
+        if (expiry_s.equals("")) {
+            expiry = null;
+        } else {
+            DateFormat format = DateFormat.getDateTimeInstance();
+            try {
+                expiry = format.parse(expiry_s);
+            } catch (ParseException e) {
+                throw new ParseFailedException("Could not parse date");
+            }
+        }
+
+        long size = Library.parseSize(size_s);
+
+        loadState();
+        String output =
+            new CommandVdCreate(name, size / Settings.SECTOR_SIZE, expiry)
+                .execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+        saveState();
+    }
+
+    public String getName() {
+        return "create";
+    }
+
+    public String getUsage() {
+        return "-n<name> -s<size> [-e<expiry>]";
+    }
+
+    public String getHelpText() {
+        return "Create a new virtual disk with the specified parameters";
+    }
 
 }
index bcd400876ed883b4c414010d3ad9aafb9cd6231a..6d4f838c4ea746dfdd3503250c71ed9640c0711b 100644 (file)
@@ -8,33 +8,38 @@ import org.xenoserver.control.Defaults;
 import org.xenoserver.control.VirtualDiskManager;
 
 public class ParseVdDelete extends CommandParser {
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    String vd_key = getStringParameter(args,'k',"");
-    
-    if ( vd_key.equals("") )
-      throw new ParseFailedException("Expected -k<key>");
-    
-    loadState();
-    if ( VirtualDiskManager.IT.getVirtualDisk(vd_key) == null )
-      throw new CommandFailedException("Virtual disk " + vd_key + " does not exist");
-      
-    String output = new CommandVdDelete(vd_key).execute();
-    if ( output != null )
-      System.out.println( output );
-      
-    saveState();
-  }
-
-  public String getName() {
-    return "delete";
-  }
-
-  public String getUsage() {
-    return "[-k<key>]";
-  }
-
-  public String getHelpText() {
-    return "Deletes the virtual disk with the specified key.";
-  }
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        String vd_key = getStringParameter(args, 'k', "");
+
+        if (vd_key.equals("")) {
+            throw new ParseFailedException("Expected -k<key>");
+        }
+
+        loadState();
+        if (VirtualDiskManager.IT.getVirtualDisk(vd_key) == null) {
+            throw new CommandFailedException(
+                "Virtual disk " + vd_key + " does not exist");
+        }
+
+        String output = new CommandVdDelete(vd_key).execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+
+        saveState();
+    }
+
+    public String getName() {
+        return "delete";
+    }
+
+    public String getUsage() {
+        return "-k<key>";
+    }
+
+    public String getHelpText() {
+        return "Deletes the virtual disk with the specified key.";
+    }
 
 }
index ea62f8998f7c29f3b64eb6bd6df0302ec0ff227b..bd7826bfabfdb622816fab0366bdf94a54371056 100644 (file)
@@ -12,34 +12,44 @@ import org.xenoserver.control.VirtualDisk;
 import org.xenoserver.control.VirtualDiskManager;
 
 public class ParseVdFree extends CommandParser {
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    boolean verbose = getFlagParameter(args, 'v');
-    
-    loadState();
-    VirtualDisk free = VirtualDiskManager.IT.getFreeDisk();
-    System.out.println( "Free disk has " + free.getExtentCount() + " extents totalling "
-                      + Library.formatSize(free.getSize()*Settings.SECTOR_SIZE,8,true) );
-    if ( verbose ) {
-      Iterator i = free.extents();
-      System.out.println("  disk       offset         size");
-      while (i.hasNext()) {
-        Extent e = (Extent) i.next();
-        System.out.println( Library.format(e.getDisk(), 6, false) + " "
-                          + Library.format(e.getOffset(), 12, false) + " "
-                          + Library.format(e.getSize(), 12, false) );
-      }
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        boolean verbose = getFlagParameter(args, 'v');
+
+        loadState();
+        VirtualDisk free = VirtualDiskManager.IT.getFreeDisk();
+        System.out.println(
+            "Free disk has "
+                + free.getExtentCount()
+                + " extents totalling "
+                + Library.formatSize(
+                    free.getSize() * Settings.SECTOR_SIZE,
+                    8,
+                    true));
+        if (verbose) {
+            Iterator i = free.extents();
+            System.out.println("  disk       offset         size");
+            while (i.hasNext()) {
+                Extent e = (Extent) i.next();
+                System.out.println(
+                    Library.format(e.getDisk(), 6, false)
+                        + " "
+                        + Library.format(e.getOffset(), 12, false)
+                        + " "
+                        + Library.format(e.getSize(), 12, false));
+            }
+        }
     }
-  }
 
-  public String getName() {
-    return "free";
-  }
+    public String getName() {
+        return "free";
+    }
 
-  public String getUsage() {
-    return "[-v]";
-  }
+    public String getUsage() {
+        return "[-v]";
+    }
 
-  public String getHelpText() {
-    return "Show free space allocated to virtual disk manager. -v enables verbose output.";
-  }
+    public String getHelpText() {
+        return "Show free space allocated to virtual disk manager. -v enables verbose output.";
+    }
 }
index be5a36616e124d4595a95fd1b4d448ca915916af..e578099e53e609c274827d5c82652181a2fc8124 100644 (file)
@@ -1,5 +1,7 @@
 package org.xenoserver.cmdline;
 
+import java.text.DateFormat;
+import java.text.ParseException;
 import java.util.Date;
 import java.util.LinkedList;
 
@@ -8,35 +10,44 @@ import org.xenoserver.control.CommandVdRefresh;
 import org.xenoserver.control.Defaults;
 
 public class ParseVdRefresh extends CommandParser {
-  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
-    String vd_key = getStringParameter(args,'k',"");
-    String expiry_s = getStringParameter(args,'e',"");
-    Date expiry;
-    
-    if ( vd_key.equals("") )
-      throw new ParseFailedException("Expected -k<key>");
-    if ( expiry_s.equals("") )
-      expiry = null;
-    else
-      expiry = new Date(Date.parse(expiry_s));
-      
-    loadState();
-    String output = new CommandVdRefresh(vd_key,expiry).execute();
-    if ( output != null )
-      System.out.println(output);
-    saveState();
-  }
-
-  public String getName() {
-    return "refresh";
-  }
-
-  public String getUsage() {
-    return "-k<key> [-e<expiry>]";
-  }
-
-  public String getHelpText() {
-    return "Refresh the expiry for the specified virtual disk. Omitting -e will cause the disk to never expire.";
-  }
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        String vd_key = getStringParameter(args, 'k', "");
+        String expiry_s = getStringParameter(args, 'e', "");
+        Date expiry;
+
+        if (vd_key.equals("")) {
+            throw new ParseFailedException("Expected -k<key>");
+        }
+        if (expiry_s.equals("")) {
+            expiry = null;
+        } else {
+            DateFormat format = DateFormat.getDateTimeInstance();
+            try {
+                expiry = format.parse(expiry_s);
+            } catch (ParseException e) {
+                throw new ParseFailedException("Could not parse date");
+            }
+        }
+
+        loadState();
+        String output = new CommandVdRefresh(vd_key, expiry).execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+        saveState();
+    }
+
+    public String getName() {
+        return "refresh";
+    }
+
+    public String getUsage() {
+        return "-k<key> [-e<expiry>]";
+    }
+
+    public String getHelpText() {
+        return "Refresh the expiry for the specified virtual disk. Omitting -e will cause the disk to never expire.";
+    }
 
 }
index af655739023bd85356dce32a10a3b5d3a2d07b16..a833d26405fc6e056d5d018f3072449aaee8466a 100644 (file)
@@ -23,23 +23,26 @@ public class ParseVdShow extends CommandParser {
       while ( i.hasNext() ) {
         VirtualDisk vd = (VirtualDisk) i.next();
         System.out.print( vd.getKey() + " " );
-        if ( vd.getExpiry() != null )
+        if ( vd.getExpiry() != null ) {
           System.out.print( vd.getExpiry().toString() );
-        else
+        } else {
           System.out.print( "                            " );
+        }
         System.out.println( " " + Library.format(vd.getName(),16,true) + " "
                           + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) );
       }
     } else {
       VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key);
-      if ( vd == null )
+      if ( vd == null ) {
         throw new CommandFailedException("There is no virtual disk " + key );
+      }
         
       System.out.println("  name: " + vd.getName());
       System.out.println("   key: " + vd.getKey());
       System.out.println("  size: " + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,true));
-      if ( vd.getExpiry() != null )
+      if ( vd.getExpiry() != null ) {
         System.out.println("expiry: " + vd.getExpiry());
+      }
       System.out.println();
  
       Iterator i = vd.extents();
@@ -58,10 +61,10 @@ public class ParseVdShow extends CommandParser {
   }
 
   public String getUsage() {
-    return "[-n<diskno>]";
+    return "[-k<key>]";
   }
 
   public String getHelpText() {
-    return "Show a summary of all virtual disks, or details of one disk if -n is given";
+    return "Show a summary of all virtual disks, or details of one disk if -k is given";
   }
 }
index 14c9288db42db16c962122e3bb48ed9d3a9e241b..b4c96f26983e89fdc7f91bd83cdc248b5100cdf9 100644 (file)
@@ -65,12 +65,16 @@ public class CommandPhysicalList extends Command {
                 outline = in.readLine();
                 while (outline != null) {
                     int disk = -1;
+                    int partition_no = -1;
                     long offset = -1;
                     long size = -1;
 
                     StringTokenizer st = new StringTokenizer(outline);
                     if (st.hasMoreTokens()) {
-                        disk = Short.parseShort(st.nextToken(), 16);
+                        disk = Integer.parseInt(st.nextToken(), 16);
+                    }
+                    if (st.hasMoreTokens()) {
+                        partition_no = Integer.parseInt(st.nextToken(), 16);
                     }
                     if (st.hasMoreTokens()) {
                         offset = Long.parseLong(st.nextToken(), 16);
@@ -80,7 +84,7 @@ public class CommandPhysicalList extends Command {
                     }
                     if (st.hasMoreTokens()) {
                         String mode = st.nextToken();
-                        Extent extent = new Extent(disk, offset, size);
+                        Extent extent = new Extent(disk, offset, size, partition_no);
                         if (mode.equals("rw")) {
                             map.put(extent, Mode.READ_WRITE);
                         } else if (mode.equals("r")) {
index 70f61f47790de006c764c6dc38135f4432d2577c..8bacadbb4938ffd8357612867d1a85d9bf8c6297 100644 (file)
@@ -169,8 +169,8 @@ public class VirtualDisk {
             Extent extent =
                 new Extent(
                     partition.getDisk(),
-                    extentSize,
-                    partition.getStartSect() + (extentSize * loop));
+                    partition.getStartSect() + (extentSize * loop),
+                    extentSize);
 
             addExtent(extent);
         }
index d495eb9c2cd3a7de7443b3c23ce0c87dfaebbe52..1f93844dd25d5facfa9d45c995c34a184b1ee493 100644 (file)
@@ -146,10 +146,11 @@ class XMLHelper {
                                 XMLHelper.getSubNode("disk", enode))),
                         Long.parseLong(
                             XMLHelper.getText(
-                                XMLHelper.getSubNode("size", enode))),
-                        Long.parseLong(
-                            XMLHelper.getText(
-                                XMLHelper.getSubNode("offset", enode))));
+                                XMLHelper.getSubNode("offset", enode))),
+                    Long.parseLong(
+                        XMLHelper.getText(
+                            XMLHelper.getSubNode("size", enode))));
+
                 vd.addExtent(extent);
             }
         }